package team.seekers.hula.auth.entity.dao;

import com.baomidou.mybatisplus.annotation.*;
import lombok.*;
import org.springframework.beans.BeanUtils;
import team.seekers.hula.auth.entity.dto.PermissionDTO;
import team.seekers.hula.common.entity.BaseDO;

import java.util.Date;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author GH
 */
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@EqualsAndHashCode(callSuper = true)
@TableName(PermissionDOField.TABLE_NAME)
public class PermissionDO extends BaseDO {

    @TableId(value = PermissionDOField.ID, type = IdType.AUTO)
    private Long id;

    @TableField(value = PermissionDOField.GMT_CREATE, fill = FieldFill.INSERT)
    private Date gmtCreate;

    @TableField(value = PermissionDOField.GMT_MODIFIED, fill = FieldFill.INSERT_UPDATE)
    private Date gmtModified;

    @TableField(PermissionDOField.IS_DELETED)
    @TableLogic(value = "0", delval = "1")
    private Integer deleted;

    @TableField(PermissionDOField.URL)
    private String url;

    @TableField(PermissionDOField.DESCRIPTION)
    private String description;

    @TableField(PermissionDOField.ROLES)
    private String roles;

    public static PermissionDTO to(PermissionDO permissionDO) {
        PermissionDTO permissionDTO = new PermissionDTO();
        BeanUtils.copyProperties(permissionDO, permissionDTO);
        return permissionDTO;
    }

    public static PermissionDO from(PermissionDTO permissionDTO) {
        PermissionDO permissionDO = new PermissionDO();
        BeanUtils.copyProperties(permissionDTO, permissionDO);
        return permissionDO;
    }

    public static List<PermissionDTO> to(List<PermissionDO> permissionDOList) {
        return permissionDOList.stream().map(PermissionDO::to).collect(Collectors.toList());
    }

    public static List<PermissionDO> from(List<PermissionDTO> permissionDTOList) {
        return permissionDTOList.stream().map(PermissionDO::from).collect(Collectors.toList());
    }
}
